package algorithm.leetcode;

public class NO283_移动零 {
    public static void main(String[] args) {

    }

    // 0 1 0 3 12
    static class Solution {
        public void moveZeroes(int[] nums) {
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] == 0) {
                    int j = i;
                    while (nums[j] == 0 && j < nums.length - 1) {
                        j++;
                    }
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
        }
    }

    static class PerformanceSolution {
        public void moveZeroes(int[] nums) {
            int slow = 0;
            for (int fast = 0; fast < nums.length; fast++) {
                if (nums[fast] != 0) {
                    nums[slow++] = nums[fast];
                }
            }
            while (slow < nums.length) {
                nums[slow++] = 0;
            }
        }
    }
}
